import type { App } from 'vue'
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import Layout from '../layout/index.vue'
import { createRouterGuard } from './guard'
const routes: RouteRecordRaw[] = [
  {
    path: '/',
    component: () => import(/* webpackChunkName: "login" */ '../views/login/index.vue'),
    name: 'login',
    meta: { hidden: false, hasAuth: false }, // 头部图片隐藏
  },
  {
    path: '/home',
    component: () => import(/* webpackChunkName: "home" */ '../views/home/index.vue'),
    name: 'home',
    meta: { hidden: true, hasAuth: false },
  },
  {
    path: '/collection',
    component: () => import(/* webpackChunkName: "home" */ '../views/collection/index.vue'),
    name: 'collection',
    meta: { hidden: true, hasAuth: false },
  },
  {
    path: '/404',
    component: () => import(/* webpackChunkName: "error" */ '../views/error/index.vue'),
    name: 'error',
    meta: {
      hidden: true,
      title: 'error',
      icon: '#icondashboard',
      affix: true,
      hasAuth: false,
    },
  },
]

export const router = createRouter({
  history: createWebHashHistory(),
  // history: createWebHashHistory('chemical-collection'),
  routes,
})

export async function setupRouter(app: App) {
  app.use(router)
  createRouterGuard(router)
  await router.isReady()
}
